package com.AAA.controller.scl;

import com.AAA.entity.*;
import com.AAA.entity.scl.TTestRecondScl;
import com.AAA.service.scl.TTestRecondSclService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * (TTestRecondScl)表控制层
 *
 * @author makejava
 * @since 2022-11-04 14:00:01
 */
@Controller
@RequestMapping("tTestRecondScl")
public class TTestRecondSclController {
    /**
     * 服务对象
     */
    @Autowired
    private TTestRecondSclService tTestRecondSclService;

    @GetMapping
    @ResponseBody
    public LayData queryAll(MyPage myPage, TTestRecondScl tTestRecondScl){
        PageInfo pageInfo = tTestRecondSclService.queryAll(myPage,tTestRecondScl);
        return new LayData(pageInfo);
    }

    @PostMapping("addHf")
    @ResponseBody
    public LayData add(HttpServletRequest request,HttpSession session){

//        return new LayData(tTestRecondSclService.addHf(request,session));
//        Integer testerId = Integer.valueOf(request.getParameter("testerId"));
        String username = request.getParameter("username");
        int testerId = tTestRecondSclService.selectIdByUsername(username);
        int i = tTestRecondSclService.selectTestId(testerId);
        if (i>0){
            return new LayData(false);
        }else {
            Boolean aBoolean = tTestRecondSclService.addHf(request, session);
            return new LayData(aBoolean);
        }
    }

    @RequestMapping("delete")
    @ResponseBody
    public LayData delete(TTestRecondScl tTestRecondScl){
            int b = tTestRecondSclService.delete(tTestRecondScl);
            return new LayData(b);

    }

    @PostMapping("updateAll")
    @ResponseBody
    public LayData updateAll(TTestRecondScl tTestRecondScl,HttpSession session){
        return new LayData(tTestRecondSclService.updateAll(tTestRecondScl,session));
    }

    @GetMapping ("tiaoZhuan")
    public String tiaoZhuan(){
        System.out.println("跳转");
        return "/scl/sclreturn";
    }
}
